home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4715 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.8 KB

  1. Path: mail2news.demon.co.uk!genesis.demon.co.uk
  2. From: Lawrence Kirby <fred@genesis.demon.co.uk>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Logical exclusive-or
  5. Date: Tue, 06 Feb 96 14:58:28 GMT
  6. Organization: none
  7. Message-ID: <823618708snz@genesis.demon.co.uk>
  8. References: <4f6lrq$bcr@lastactionhero.rs.itd.umich.edu> <4f7688$4te@beach.and.nl>
  9. Reply-To: fred@genesis.demon.co.uk
  10. X-NNTP-Posting-Host: genesis.demon.co.uk
  11. X-Newsreader: Demon Internet Simple News v1.27
  12. X-Mail2News-Path: genesis.demon.co.uk
  13.  
  14. In article <4f7688$4te@beach.and.nl> jos@and.nl "Jos A. Horsmeier" writes:
  15.  
  16. >In article <4f6lrq$bcr@lastactionhero.rs.itd.umich.edu>, davidm@umich.edu 
  17. >wrote:
  18. >
  19. >|Is there a good reason why C doesn't have a logical exclusive-or
  20. >|operator?  A look at the precedence hierarchy suggests an obvious
  21. >|symbol and precedence for such an operator:
  22. >|
  23. >|        bitwise and             &
  24. >|        bitwise exclusive or    ^
  25. >|        bitwise inclusive or    |
  26. >|        logical and             &&
  27. >|        logical or              ||
  28. >|
  29. >|The logical exclusive or would be represented by ^^ and have
  30. >|precedence higher than || but lower than && .  If C requires machines
  31. >|to be able to implement bitwise XOR, then it would seem reasonable to
  32. >|require the logical operator also.
  33.  
  34. It is the nature of C to tend towards minimalism which is one of the
  35. reasons it is a good and successful language (I'm not saying everything in
  36. the language can be justified on this basis). You seem to be asking 'why
  37. isn't it in the language' whereas the correct question is 'why should it
  38. be in the language'? In that particular case it adds little or nothing
  39. to the language hence is correctly left out. Another way of looking at it
  40. is that ANSI (mostly) standardised 'existing practice'. Since none of the
  41. existing C implementations at the time thought ^^ useful  the ANSI committee
  42. didn't either. 
  43.  
  44. >Note that although the logical 'and' and 'or' operators do not 
  45. >evaluate their right operand if their left operand is false or
  46. >true resepectively, the 'logical exclusive or' operator must
  47. >evaluate both operands no matter what the value of the left hand
  48. >operand is. So the sole purpose of a '^^' operator would be a lexical
  49. >shorthand for: 
  50. >
  51. >        a ^^ b == (!(a) != !(b)) 
  52.  
  53. They do define sequence points between their operands which can be
  54. simulated for '^^' with:
  55.  
  56. #define LXOR(a,b) ((a) ? !(b) : !!(b))
  57.  
  58. >That wouldn't be much of added functionality, would it?
  59.  
  60. Right. It may be useful once in a blue moon but that's not a good enough
  61. reason to add something to a language given that the same functionality
  62. can be simulated easily enough with existing language constructs.
  63.  
  64. -- 
  65. -----------------------------------------
  66. Lawrence Kirby | fred@genesis.demon.co.uk
  67. Wilts, England | 70734.126@compuserve.com
  68. -----------------------------------------
  69.